package com.mac.intellect_flow.framework.model;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.mac.intellect_flow.base.UserBaseDto;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.util.Collection;
import java.util.Set;

/**
 * 登录用户身份权限
 * 
 * @author mac
 */
@EqualsAndHashCode(callSuper = true)
@Data
public class LoginUser extends UserBaseDto implements UserDetails {
    private static final long serialVersionUID = 1L;

    /**
     * 部门ID
     */
    private Long deptId;

    private Long deptName;

    /**
     * 用户唯一标识
     */
    private String token;

    private String password;

    /**
     * 登录时间
     */
    private Long loginTime;

    /** 用户头像 */
    private String avatar;

    /**
     * 登录IP地址
     */
    private String ipaddr;

    /**
     * 登录地点
     */
    private String loginLocation;

    /**
     * 权限列表
     */
    private Set<String> permissions;


    private Set<String> roles;

    private Collection<? extends GrantedAuthority> authorities;



    public LoginUser() {
    }



    @JsonIgnore
    @Override
    public String getPassword()
    {
        return this.password;
    }

    @Override
    public String getUsername() {
        return super.username;
    }

    /**
     * 账户是否未过期,过期无法验证
     */
    @JsonIgnore
    @Override
    public boolean isAccountNonExpired()
    {
        return true;
    }

    /**
     * 指定用户是否解锁,锁定的用户无法进行身份验证
     * 
     * @return
     */
    @JsonIgnore
    @Override
    public boolean isAccountNonLocked()
    {
        return true;
    }

    /**
     * 指示是否已过期的用户的凭据(密码),过期的凭据防止认证
     * 
     * @return
     */
    @JsonIgnore
    @Override
    public boolean isCredentialsNonExpired()
    {
        return true;
    }

    /**
     * 是否可用 ,禁用的用户不能身份验证
     * 
     * @return
     */
    @JsonIgnore
    @Override
    public boolean isEnabled()
    {
        return true;
    }

    @Override
    public Collection<? extends GrantedAuthority> getAuthorities()
    {
        return authorities;
    }
}
